/***************************************************************************
 *   zlib SDL_rwops stream test                                            *
 *                                                                         *
 *   Copyright (C) 2004 by Tyler Montbriand                                *
 *   tsm@accesscomm.ca                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "SDL_rwbz2.h"
#include "SDL_rwprintf.h"

int main(int argc, char *argv[])
{
  int retval=0;
  char buf[512];
  int size;
  SDL_RWops *bz2=SDL_RWFromBZ2("testdata/testinput.bz2","r");

  if(bz2!=NULL)
  {
    fprintf(stderr,"Output of testdata/testinput.bz2 is as follows:\n");
    while((size=SDL_RWread(bz2,buf,1,512))>0)
      fwrite(buf,1,size,stdout);

    SDL_RWclose(bz2);
  }
  else
  {
    fprintf(stderr,"Couldn't open test file.\n");
    retval++;
  }

  bz2=SDL_RWFromBZ2("testout.bz2","w9");
  if(bz2==NULL)
  {
    fprintf(stderr,"Couldn't open output file\n");
  }
  else if(rwprintf(bz2,"Testing Testing 1 2 3\n")<=0)
  {
    fprintf(stderr,"Couldn't write to bz2\n");
    SDL_RWclose(bz2);
    retval++;
  }  
  else
  {
    fprintf(stderr,"Compressed '%s' to testout.bz2\n","Testing Testing 1 2 3");
    SDL_RWclose(bz2);
  }

  return(retval);
}
